package szzy

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
	"github.com/flipped-aurora/gin-vue-admin/server/model/szzy"
	szzyReq "github.com/flipped-aurora/gin-vue-admin/server/model/szzy/request"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type StudentProfileApi struct{}

// CreateStudentProfile 创建学生档
// @Tags StudentProfile
// @Summary 创建学生档
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body szzy.StudentProfile true "创建学生档"
// @Success 200 {object} response.Response{msg=string} "创建成功"
// @Router /SP/createStudentProfile [post]
func (SPApi *StudentProfileApi) CreateStudentProfile(c *gin.Context) {
	var SP szzy.StudentProfile
	err := c.ShouldBindJSON(&SP)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = SPService.CreateStudentProfile(&SP)
	if err != nil {
		global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("创建成功", c)
}

// DeleteStudentProfile 删除学生档
// @Tags StudentProfile
// @Summary 删除学生档
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body szzy.StudentProfile true "删除学生档"
// @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /SP/deleteStudentProfile [delete]
func (SPApi *StudentProfileApi) DeleteStudentProfile(c *gin.Context) {
	ID := c.Query("ID")
	err := SPService.DeleteStudentProfile(ID)
	if err != nil {
		global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("删除成功", c)
}

// DeleteStudentProfileByIds 批量删除学生档
// @Tags StudentProfile
// @Summary 批量删除学生档
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
// @Router /SP/deleteStudentProfileByIds [delete]
func (SPApi *StudentProfileApi) DeleteStudentProfileByIds(c *gin.Context) {
	IDs := c.QueryArray("IDs[]")
	err := SPService.DeleteStudentProfileByIds(IDs)
	if err != nil {
		global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("批量删除成功", c)
}

// UpdateStudentProfile 更新学生档
// @Tags StudentProfile
// @Summary 更新学生档
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body szzy.StudentProfile true "更新学生档"
// @Success 200 {object} response.Response{msg=string} "更新成功"
// @Router /SP/updateStudentProfile [put]
func (SPApi *StudentProfileApi) UpdateStudentProfile(c *gin.Context) {
	var SP szzy.StudentProfile
	err := c.ShouldBindJSON(&SP)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = SPService.UpdateStudentProfile(SP)
	if err != nil {
		global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("更新成功", c)
}

// FindStudentProfile 用id查询学生档
// @Tags StudentProfile
// @Summary 用id查询学生档
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query szzy.StudentProfile true "用id查询学生档"
// @Success 200 {object} response.Response{data=szzy.StudentProfile,msg=string} "查询成功"
// @Router /SP/findStudentProfile [get]
func (SPApi *StudentProfileApi) FindStudentProfile(c *gin.Context) {
	ID := c.Query("ID")
	//requestURL := c.Request.URL.String()
	//
	//// 获取查询参数
	//queryParams := c.Request.URL.Query()
	//global.GVA_LOG.Info("查询参数", zap.Any("queryParams", queryParams))
	//println("requestURL--------------------:", requestURL)
	//println(" ID--------------------:", ID)
	reSP, err := SPService.GetStudentProfile(ID)
	if err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败:"+err.Error(), c)
		return
	}
	response.OkWithData(reSP, c)
}

// GetStudentProfileList 分页获取学生档列表
// @Tags StudentProfile
// @Summary 分页获取学生档列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query szzyReq.StudentProfileSearch true "分页获取学生档列表"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
// @Router /SP/getStudentProfileList [get]
func (SPApi *StudentProfileApi) GetStudentProfileList(c *gin.Context) {
	var pageInfo szzyReq.StudentProfileSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	list, total, err := SPService.GetStudentProfileInfoList(pageInfo)
	if err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败:"+err.Error(), c)
		return
	}
	response.OkWithDetailed(response.PageResult{
		List:     list,
		Total:    total,
		Page:     pageInfo.Page,
		PageSize: pageInfo.PageSize,
	}, "获取成功", c)
}

// GetStudentProfilePublic 不需要鉴权的学生档接口
// @Tags StudentProfile
// @Summary 不需要鉴权的学生档接口
// @accept application/json
// @Produce application/json
// @Param data query szzyReq.StudentProfileSearch true "分页获取学生档列表"
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
// @Router /SP/getStudentProfilePublic [get]
func (SPApi *StudentProfileApi) GetStudentProfilePublic(c *gin.Context) {
	// 此接口不需要鉴权
	// 示例为返回了一个固定的消息接口，一般本接口用于C端服务，需要自己实现业务逻辑
	SPService.GetStudentProfilePublic()
	response.OkWithDetailed(gin.H{
		"info": "不需要鉴权的学生档接口信息",
	}, "获取成功", c)
}
